package com.rrd.dw.mr.gzip.kafka;

import com.ucredit.babel.common.model.BaseModel;
import com.ucredit.babel.common.model.RecordType;
import com.ucredit.babel.common.model.baiwei.BaiweiFraudScoreRecord;
import com.ucredit.babel.common.model.baiwei.BaiweiScore;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper.Context;

import java.io.IOException;

/**
 * 百维欺诈分
 * @author rrz
 */

public class BaiweiFraudScoreParse extends ParseBase {
     private Text val = new Text();
     private Text key = new Text();

    /**
     *
     *百维欺诈分
     * @param model
     * @throws IOException
     * @throws InterruptedException
     */
    @Override
    public boolean parseJob(Context context, BaseModel<?> model, String successful) throws IOException, InterruptedException {
        BaiweiFraudScoreRecord obj = (BaiweiFraudScoreRecord)model;
        BaiweiScore score = obj.getScore();
        StringBuilder sb = getBaseInfo(obj, successful);

        //返回提示  msg
        sb.append(score.getMsg()).append(CRT001);
        //若status为0则此处会填写对应的错误编码  code
        sb.append(score.getCode()).append(CRT001);
        //1为查得，2为查询  checkResult
        sb.append(score.getCheckResult()).append(CRT001);
        //1：成功；0：失败  status
        sb.append(score.getStatus()).append(CRT001);
        //值区间在0.0~100之间(0.0算未查得)，值越大代表行为的风险程度越大  score
        sb.append(score.getScore()).append(CRT001);
        StringBuilder txSb = getBaseInfo(obj);
        key.set(getKey());
        val.set((sb.toString() + txSb.toString()).replace("\n","").replace("\r", " "));
        context.write(key,val);
        return true;

    }

    @Override
    public String getTableName() {
        return "kafka_babel_baiwei_fraud_score_inc";
    }

    @Override
    public String getType() {
        return RecordType.BAIWEI_FRAUD_SCORE_RECORD.toString();
    }

    @Override
    public String getComment() {
        return "百维欺诈分";
    }
}
